﻿using ConfExpert.Forms.Base;
using ConfExpert.Utility;
using DevExpress.XtraEditors;
using DevTeam;


using System;
using System.Collections.Generic;
using System.Data;

namespace ConfExpert.Forms.Depo
{
    public partial class BenzerRenkler2 : XForm
    {
        DataTable dtMuadil;
        public BenzerRenkler2(Dictionary<int, List<int>> _muadil, Dictionary<int, int> _ihtiyac)
        {
            InitializeComponent();

            this.Text = "MuadilAra";

            dtMuadil = new DataTable("M");
            dtMuadil.Columns.Add("ProductId", typeof(int));
            dtMuadil.Columns.Add("OrderMts", typeof(int));
            dtMuadil.Columns.Add("MuadilId", typeof(int));
            dtMuadil.Columns.Add("Nr", typeof(int));
            if (!ds.Tables.Contains("M"))
                ds.Tables.Add(dtMuadil);

            foreach (KeyValuePair<int, List<int>> m in _muadil)
            {
                int sira = 0;
                foreach (int item in m.Value)
                    dtMuadil.Rows.Add(m.Key, _ihtiyac[m.Key], item, ++sira);
            }
        }

        private void BenzerRenkler2_Load(object sender, EventArgs e)
        {

            gridView1.Init("GetStokCK", dtMuadil.SerializeChanges());
            gridView1.AddDetailGrid(gridView2, "P");
            gridView2.AddDetailGrid(gridView3, "ProductId");

            gridView1.SetCaptions("OrderMts:EksikMt");
            gridView1.MakeColumnInvisible("P");
            gridView1.FormatAsNumber(1, "OrderMts");
            gridView1.AddSummary("OrderMts");

            gridView2.MakeColumnInvisible("P");
            gridView2.FormatAsNumber(1, "IdleQty", "RsvdQty");
            gridView2.AddSummary("IdleQty", "RsvdQty");

            //gridView3.MakeColumnInvisible("ProductId", "Scan");
            gridView3.FormatAsNumber(1, "Qty");
            gridView3.AddSummary("Qty");

            splitContainerControl1.SizeChanged += new EventHandler(SizeChanged1);
            splitContainerControl2.AutoSize();

            gridView1.BestFitColumns();
            gridView2.BestFitColumns();
            gridView3.BestFitColumns();

            gridView1.FocusedRowChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventHandler(gridView1_FocusedRowChanged);
        }

        void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            int pid = gridView1.GetFocusedRowCellValue("ProductId").ToInt();
            if (pid > 0)
                txtInfo.Caption = AppSession.Lookups.V_Kumas.FindByProductId(pid).Name;
        }


        public void SizeChanged1(object sender, EventArgs e)
        {
            SplitContainerControl scc = ((SplitContainerControl)sender);
            //scc.SizeChanged -= SizeChanged1;
            //SetSplitterPosition(sender as SplitContainerControl);
            scc.SplitterPosition = (scc.Horizontal ? scc.Width : scc.Height) / 3;
        }
    }
}
